﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using IntelligentPharmacy.Entity;
using IntelligentPharmacy.publicclass;
using SmartForcer;
using SmartRoom;

namespace ConsumablesCabinet
{
    class Global
    {
        public static MessageWindow MessageWindow = new MessageWindow();
        /// <summary>
        /// 读写器com口和功率
        /// </summary>
        public static string readIP;
        public static string MainForcer;
        public static int FingerCheckValue=40;
        public static List<UserFace> listuserFace = new List<UserFace>();

        public static List<Window> WindowsList = new List<Window>();
        public static long SystemIdelTime = 0;
        /// <summary>
        /// 设备id和spd系统 id
        /// </summary>
        public static SpdId spdNameOrDreiceName;
        #region 天线的配置参数
        /// <summary>
        /// <!--每条命令的盘存次数:默认是1-->
        /// </summary>
        public static byte btRepeat = 1;
        /// <summary>
        /// 是否开启自定义session默认是不开启
        /// </summary>
        public static bool RealSession = false;
        /// <summary>
        /// 0:session0;1:session1;2:session2;3:session3;99为默认
        /// </summary>
        public static int Session;
        /// <summary>
        /// Inventoried Flag: 默认是1
        /// </summary>
        public static byte btTarget = 0;
        /// <summary>
        /// 
        /// </summary>
        public static string tdjTDJAerial;
        #endregion
        /// <summary>
        /// 锁关闭的时间
        /// </summary>
        public static int LockTime;
        /// <summary>
        /// 用户信息
        /// </summary>
        public static UserFace User;

        public static int readTime;

        public static Dictionary<string, int> comeAndPower = new Dictionary<string, int>();

        /// <summary>
        /// 当前库房所有的rfid标签第一次读取的时候要保存下---------------------------------------------
        /// </summary>
        public static Dictionary<string, string> AfterRfidList = new Dictionary<string, string>();

        public static bool LoadConfig()
        {
            ConfigManager config = new ConfigManager();
            try
            {
                LockTime = Convert.ToInt32(config.GetAppSetting("LockTime"));
                MainForcer = config.GetAppSetting("MainComeName");
                readIP = config.GetAppSetting("ReadIP");
                comeAndPower = getComeAndPower(readIP);
                tdjTDJAerial=config.GetAppSetting("TDJAerial");
                readTime = Convert.ToInt32(config.GetAppSetting("readTime"));
                RealSession = Convert.ToBoolean(config.GetAppSetting("RealSession"));
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public static Dictionary<string, int> getComeAndPower(string value)
        {
            Dictionary<string, int> map = new Dictionary<string, int>();
            string[] comename = value.Split(',');
            foreach (string c in comename)
            {
                string[] comePower = c.Split(':');
                map.Add(comePower[0], Convert.ToInt32(comePower[1]));
            }

            return map;
        }
    }
}
